package pub.gll.onepeas.libbase.track.manager

import pub.gll.onepeas.libbase.track.holder.ExposureHolder
import pub.gll.onepeas.libbase.track.model.ExposureInner
import pub.gll.onepeas.libbase.track.util.ExposureDataManager
import pub.gll.onepeas.libbase.track.constants.ViewExposureConstants
import pub.gll.onepeas.libbase.track.model.ExposureModel

/**
 * <pre>
 *     @author : whg
 *     @e-mail : guanhuawei@kkworld.com
 *     @time   : 2021/12/3 11:03
 *     @desc   : 曝光专用runnable，处理曝光计算逻辑
 *     @version: 1.0
 * </pre>
 */
internal class ExposureHandlerRunnable(private val exposureHolder: ExposureHolder?, private val what: Int, private val obj: Any?) : Runnable {

    override fun run() {
        when (what) {
            //单个处理
            KKExposureManager.SINGLE_COMMIT_EXPOSURE -> {
                val exposureInner = obj as? ExposureInner
                when (exposureInner?.triggerType) {
                    ViewExposureConstants.TRIGGER_WINDOW_CHANGED -> {
                        exposureHolder?.exposureWindowChange(exposureInner)
                    }

                    ViewExposureConstants.TRIGGER_VIEW_CHANGED -> {
                        exposureHolder?.exposureViewChange(exposureInner)
                    }
                }
            }
            //单独处理view不显示
            KKExposureManager.HANDLE_VIEW_DISEXPOSURE -> {
                with(obj as? ExposureModel) {
                    ExposureDataManager.onViewInVisible(this)
                }
            }
            else -> {
            }
        }
    }
}